<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class T_PM_PROJECT_BASE extends Model
{
    public $table='T_PM_PROJECT_BASE';
    public $connection='mysql';
    public function index(){
      $list=$this->field('ID,PROJECT_NO,STATUS,PLAN_END_TIME,ACTUAL_END_TIME,CLOSE_TIME,CUST_CODE,PLAN_END_TIME,CREATE_TIME,MODEL_CODE')->select()->toArray();
      return $list;
    }
    public function produce($day){
       $list=$this->where([['CREATE_TIME','>=',date('Y-m-d 00:00:00',strtotime('-'."$day".'day'))],['CREATE_TIME','<=',date('Y-m-d 23:59:59')]])
           ->field('ID,PLAN_END_TIME,CREATE_TIME,ACTUAL_END_TIME,PROJECT_NO')
           ->select()->toArray();
       return $list;
    }
    public function sc_gd_gj_count($day,$status=[]){
        $where[]=['CREATE_TIME','>=',date('Y-m-d',strtotime('-'."$day".'day'))];
        $where[]=['CREATE_TIME','<=',date('Y-m-d')];
        $list=$this->where([['STATUS','in',$status]])->where($where)->count('ID');
        return $list;
    }
    public function sc_gd_wj_zq($day,$order='asc'){
        $where[]=['CREATE_TIME','>=',date('Y-m-d',strtotime('-'."$day".'day'))];
        $where[]=['CREATE_TIME','<=',date('Y-m-d')];
        $where[]=['CLOSE_TIME','<>',''];
        $list=$this->where($where)->field('DATEDIFF(day,CREATE_TIME,CLOSE_TIME) as time')->order('time',"$order")->find()->toArray();
        return $list;
    }
    public function sc_gd_cz_bl($day){
        $where[]=['CREATE_TIME','>=',date('Y-m-d',strtotime('-'."$day".'day'))];
        $where[]=['CREATE_TIME','<=',date('Y-m-d')];
        $list=$this->where($where)->field('CREATE_TIME,CLOSE_TIME')->select()->toArray();
        return $list;
    }
    public function sc_gd_bl_avg($day,$order='asc'){
        $where_gd_NG[]=['CREATE_TIME','>=',date('Y-m-d',strtotime('-'."$day".'day'))];
        $where_gd_NG[]=['INPUT_QTY','<>',0];
        $where_gd_NG[]=['OUTPUT_QTY','<>',0];
        $list=$this->where($where_gd_NG)->where('OUTPUT_QTY <= INPUT_QTY')->field('1-OUTPUT_QTY/INPUT_QTY as NG,PROJECT_NO')->order('NG',"$order")->find()->toArray();
        return $list;
    }
}
